#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
	bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {

		stack<int> st;//创建一个栈
		int pushi = 0;//pushed的遍历下标
		int popi = 0;//poped的遍历下标

		while (pushi < pushed.size())//入栈序列是否走完
		{
			st.push(pushed[pushi++]);//入栈

			while (!st.empty() && st.top() == popped[popi])//循环判断 先判空 再判是否相等
			{
				st.pop();//不空且相等则pop 模拟出栈
				popi++;//出栈序列的下标++

			}
		}

		// return st.empty();
		return popi == popped.size();//遍历完出栈序列 应该与size()相等  
	}
};